package com.crm.controller;

import com.crm.pojo.common.BaseProperties;
import com.crm.pojo.common.PageResult;
import com.crm.pojo.common.Result;
import com.crm.pojo.common.StatisticsResult;
import com.crm.pojo.domain.ActivityNum;
import com.crm.pojo.domain.ChannelNum;
import com.crm.pojo.domain.Contract;
import com.crm.pojo.dto.ActivityStatisticsDto;
import com.crm.pojo.dto.CluesStatisticsDto;
import com.crm.pojo.dto.ContractStatisticsListDto;
import com.crm.pojo.vo.SubjectStatisticsVo;
import com.crm.service.ActivityNumService;
import com.crm.service.ChannelNumService;
import com.crm.service.ContractService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @Author: xaw
 * @CreateTime: 2025-09-06  09:05:56
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/report")
public class ReportController {
    private final ContractService contractService;
    private final ChannelNumService channelNumService;
    private final ActivityNumService activityNumService;

    /**
     * 获取客户统计报表 分页查询
     *
     * @param contractStatisticsListDto
     * @return
     */
    @GetMapping("/contractStatisticsList")
    public PageResult contractStatisticsList(ContractStatisticsListDto contractStatisticsListDto) {
        return contractService.getContractStatisticsList(contractStatisticsListDto);
    }

    /*/api/report/deptStatisticsList/2025-08-31/2025-09-07?pageNum=1&pageSize=10&beginCreateTime=2025-08-31&endCreateTime=2025-09-07*/

    /**
     * 部门数据列表
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @param baseProperties
     * @return
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public PageResult deptStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime, BaseProperties baseProperties) {
        return contractService.getDeptStatisticsList(beginCreateTime, endCreateTime, baseProperties);
    }

    /* /cluesStatisticsList?pageNum=1&pageSize=10&beginCreateTime=2025-08-31&endCreateTime=2025-09-07&id=&owner=&post= */
    @GetMapping("/cluesStatisticsList")
    public PageResult cluesStatisticsList(CluesStatisticsDto cluesStatisticsDto) {
        return contractService.getCluesStatisticsList(cluesStatisticsDto);
    }

    /* /activityStatisticsList?beginCreateTime=2025-08-31&endCreateTime=2025-09-07&code=&name=&total=0&pageNum=1&pageSize=10 */
    @GetMapping("/activityStatisticsList")
    public PageResult activityStatisticsList(ActivityStatisticsDto activityStatisticsDto) {
        return contractService.getActivityStatisticsList(activityStatisticsDto);
    }

    /**
     * 获取 客户统计图--计算指定日期的新增客户数
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public StatisticsResult contractStatisticsByCreateTime(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return contractService.getContractStatistics(beginCreateTime, endCreateTime);
    }

    /* path:"/report/subjectStatistics/2025-08-31/2025-09-07" */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public Result getsubjectStatisticsByCreateTime(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        List<SubjectStatisticsVo> list = contractService.getSubjectStatistics(beginCreateTime, endCreateTime);
        return Result.success(list);
    }

    /* /report/salesStatistics/2025-08-31/2025-09-07 */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    public StatisticsResult getSalesStatisticsByCreateTime(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return contractService.getContractStatistics(beginCreateTime, endCreateTime);
    }

    /* "/report/cluesStatistics/2025-08-31/2025-09-07" */

    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    public StatisticsResult getCluesStatisticsByCreateTime(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        return contractService.getContractStatistics(beginCreateTime, endCreateTime);
    }

    /* /api/report/activityStatistics/2025-08-07/2025-09-02 */
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public Result getActivityStatisticsByCreateTime(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        List<ActivityNum> list = activityNumService.list();
        return Result.success(list);
    }

    /* /report/chanelStatistics/2025-08-31/2025-09-07" */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public Result getChannelNumStatisticsByCreateTime(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        List<ChannelNum> list = channelNumService.list();
        return Result.success(list);
    }

}
